use sqlx::{sqlite::SqlitePoolOptions, Pool, Sqlite};
use anyhow::Result;

pub mod users;

pub struct DataBase{
    db_pool: Pool<Sqlite>,
}
impl DataBase {
    pub async fn new() -> Result<Self> {
        let db_pool = SqlitePoolOptions::new()
        .max_connections(5)
        .connect("sqlite:C:\\Users\\semi\\code\\ztools\\src-tauri\\src\\db\\ztools.db").await?;
        Ok(DataBase { db_pool})
    }
}

#[tokio::test]
async fn test_db() -> Result<()>{
    let pool = DataBase::new().await?.db_pool;
    let zusers = sqlx::query_as::<_,users::Users>("select * from users").fetch_all(&pool).await?;

    println!("{:#?}",zusers);
    Ok(())
}